package com.qf.om.servlet;

import com.qf.om.entity.Admin;
import org.apache.commons.io.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

@WebServlet(urlPatterns = "/showheader")
public class HeaderShowServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Admin admin = (Admin) req.getSession().getAttribute("login_user");
        String header = admin.getHeader();
        System.out.println("获取用户头像的名称：" +header);
        //头像的File对象
        File headerfile=new File(RegisterFileServlet.uploaderPath+header);
        try(
                InputStream is = new FileInputStream(headerfile);
                OutputStream os = resp.getOutputStream()
        ) {
            IOUtils.copy(is,os);
        }

    }
}
